package com.example.qt.ptplatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qt.ptplatform.dto.TorrentReportDataDTO;
import com.example.qt.ptplatform.entity.TorrentReport;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TorrentReportMapper extends BaseMapper<TorrentReport> {
    @Select("SELECT uploaded, downloaded FROM torrent_report WHERE user_id = #{userId}")
    List<TorrentReportDataDTO> selectByUserId(@Param("userId") int userId);
    /**
     * 获取指定种子的当前做种人数
     * 做种者定义为 left = 0 且最近 30 分钟内有上报记录的用户
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM torrent_report " +
            "WHERE info_hash = #{infoHash} " +
            "AND `left` = 0 " +
            "AND report_time >= DATE_SUB(NOW(), INTERVAL 30 MINUTE)")
    int countCurrentSeeders(@Param("infoHash") String infoHash);
}

